"""POI routes."""
from flask import request, current_app
from flask_restx import Namespace, Resource, fields
from app.models.poi import POI
from app.routes.mock_data import get_poi_introduction, get_mock_pois

api = Namespace('poi', description='POI operations')

# Models
introduction_query_model = api.model('IntroductionQuery', {
    'location': fields.Raw(description='Current location for weather context'),
    'voice': fields.String(description='TTS voice (alloy, echo, fable, onyx, nova, shimmer)', default='alloy')
})


@api.route('/<string:poi_id>/introduction')
class POIIntroduction(Resource):
    """POI introduction endpoint."""
    
    def get(self, poi_id):
        """Get POI introduction with optional TTS.
        
        Validates: Requirements 2.3, 2.4
        """
        # Try to get POI from database first
        poi = POI.query.get(poi_id)
        
        if poi:
            poi_name = poi.name
        else:
            # Use mock data
            mock_pois = get_mock_pois(31.9729, 120.9068)
            mock_poi = next((p for p in mock_pois if p['id'] == poi_id), None)
            poi_name = mock_poi['name'] if mock_poi else '未知景点'
        
        # Get introduction from mock data
        introduction_text = get_poi_introduction(poi_id)
        
        response = {
            'poi_id': poi_id,
            'poi_name': poi_name,
            'introduction': introduction_text,
            'audio': None,  # 配音文件置空
            'audio_format': None,
            'is_mock': True
        }
        
        return response, 200
